﻿@{
    ViewBag.Title = "用户管理";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="ibox">
    <div class="ibox-content">
        <div class="div_find">
            <div>
                <label class="find_labela">登录名：</label>
                <input type="text" class="find_input" id="userName" />
                <label class="find_labela">昵称：</label>
                <input type="text" class="find_input" id="nickName" />
                <button type="button" class="btn btn-primary" onclick="query();">查询</button>
            </div>
        </div>
        <div id="toolbar" class="btn-group">
        </div>
        <table id="userTable"></table>
    </div>

</div>
@section scripts
{
    <script>
        var $userTable;
        $(function() {
            loadGrid();
        });

        function loadGrid() {
            $userTable=$("#userTable").bootstrapTable({
                url: '/admin/sysuser/getdata',
                toolbar: '#toolbar',       
                pagination: true,
                height: $(window).height()-50,
                pageSize: 15,
                pageList: [5, 10, 15, 20],
                showColumns: true,
                showRefresh: true,
                clickToSelect: true, 
                sidePagination: "server", 
                locale: "zh-CN",
                striped: true,
                queryParams: function (params) {
                    var dto = {
                        limit: params.limit, //每页多少条
                        offset: params.offset, //从第几条开始读(默认就好)
                        userName: $('#userName').val(),
                        nickName:$('#nickName').val()
                    };
                    return dto;
                },
                columns: [
                    { field: 'ck', checkbox: true },
                    { field: 'AccountName', title: '登录名', align: 'center' },
                    { field: 'RealName', title: '用户名', align: 'center' },
                    {
                        field: 'IsSuper', title: '是否超管', align: 'center', formatter: function (v) {
                            if (v) {
                                return '<span class="label label-primary">是</span>';
                            }
                            return '-';
                        }
                    },
                    { field:"DeptName",title:"部门",align:'center'},
                    { field: 'RoleName', title: '角色名称', align: 'center'  },
                    { field: 'MobilePhone', title: '联系方式', align: 'center'  },
                    { field: 'Email', title: '邮箱', align: 'center' },
                    { field: 'Id', title: '操作', align: 'center', formatter: renderOpts }
                ]
                
            });
            jutils.initToolBarRole('#toolbar');
        }

        function renderOpts(v, d, i) {
            return jutils.initToolBarRow(v);
        }
        function add() {
            location.href = '/admin/SysUser/form?id=0';
        }

        function edit(obj) {
            var id = $(obj).data('id');
            location.href = '/admin/SysUser/form?id=' + id;
        }

        function del(obj) {
            var id = $(obj).data('id');
            jutils.confirm('确认删除吗',
                function() {
                    jutils.ajaxGet('/admin/SysUser/DelUserByIds',
                        { ids: id},
                        function() {
                            $userTable.bootstrapTable('refresh');
                        });
                });
        }

        function query() {
            $userTable.bootstrapTable('refresh');
        }

    </script>
}